package com.sun.rabbit.workQueues;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.sun.rabbit.utils.RabbitMqUtils;

/**
 * @author shkstart
 * @create 2021-10-14 16:24
 */
public class Work01_1 {
    private static final String QUEUE_NAME="hello";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        System.out.println("c1消费者等待消费（接收消息）。。。");
        DeliverCallback deliverCallback = (consumerTag, delivery)->{
            String message = new String(delivery.getBody(),"utf-8");
            System.out.println("接收到的消息:"+message);
            /**
             * 1.表示消息标识
             * 2. ture:应答所有消息包括传递过来的消息
             *   false:只应答接收到的消息
             */
            channel.basicAck(delivery.getEnvelope().getDeliveryTag(),false);
        };
        CancelCallback cancelCallback=(consumerTag)->{
            System.out.println(consumerTag+" 消费者取消消费接口回调逻辑");
        };
        //手动应答
        boolean autoAck=false;
        channel.basicConsume(QUEUE_NAME,autoAck,deliverCallback,cancelCallback);
    }
}
